package com.freak.neteasecloudmusic.modules.find.recommend.songlist.fragment.adapter;

import android.content.Context;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.freak.neteasecloudmusic.R;
import com.freak.neteasecloudmusic.modules.find.recommend.base.entity.RecommendEveryDayEntity;
import com.freak.neteasecloudmusic.modules.find.recommend.songlist.fragment.entity.PlaylistsEntity;
import com.freak.neteasecloudmusic.modules.find.recommend.songlist.fragment.entity.RecommendEntity;
import com.freak.neteasecloudmusic.utils.StringUtils;

import java.util.List;


public class SongListFragmentAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    private Context mContext;
    public static final int RECOMMEND_SONG_LIST = 0;
    public static final int NEW_SONG_LIST = 1;
    public static final int SONG_LIST = 2;
    public static final int RECOMMEND_EVERY_DAY = 3;

    public SongListFragmentAdapter(List<MultiItemEntity> data, Context mContext) {
        super(data);
        this.mContext = mContext;
        addItemType(RECOMMEND_SONG_LIST, R.layout.item_song_list);
        addItemType(SONG_LIST, R.layout.item_song_list);
        addItemType(NEW_SONG_LIST, R.layout.item_new_song);
        addItemType(RECOMMEND_EVERY_DAY, R.layout.item_song_list);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, MultiItemEntity item) {
        switch (item.getItemType()) {
            //推荐歌单
            case RECOMMEND_SONG_LIST:
                RecommendEntity.ResultBean resultBean= (RecommendEntity.ResultBean) item;
                Glide.with(mContext).load(resultBean.getPicUrl()).thumbnail(0.1f).into((ImageView) helper.getView(R.id.imageViewSongListItemBg));
                helper.setText(R.id.textViewSongContext, resultBean.getName());
                helper.setText(R.id.textViewSongListListenerCount, StringUtils.toOneHundredThousand(resultBean.getPlayCount()));
                break;
            case SONG_LIST:
                PlaylistsEntity playlistsEntity= (PlaylistsEntity) item;
                Glide.with(mContext).load(playlistsEntity.getCoverImgUrl()).thumbnail(0.1f).into((ImageView) helper.getView(R.id.imageViewSongListItemBg));
                helper.setText(R.id.textViewSongContext, playlistsEntity.getName());
                helper.setText(R.id.textViewSongListListenerCount, StringUtils.toOneHundredThousand(Long.parseLong(playlistsEntity.getPlayCount())));
                break;
            case RECOMMEND_EVERY_DAY:
                RecommendEveryDayEntity.RecommendBean recommendEveryDayEntity= (RecommendEveryDayEntity.RecommendBean) item;
                Glide.with(mContext).load(recommendEveryDayEntity.getPicUrl()).thumbnail(0.1f).into((ImageView) helper.getView(R.id.imageViewSongListItemBg));
                helper.setText(R.id.textViewSongContext, recommendEveryDayEntity.getName());
                helper.setText(R.id.textViewSongListListenerCount, StringUtils.toOneHundredThousand(recommendEveryDayEntity.getPlaycount()));

                break;
            default:
                break;
        }

    }
}
